home *** CD-ROM | disk | FTP | other *** search
/ SGI Freeware 1999 August / SGI Freeware 1999 August.iso / dist / fw_gimp.idb / usr / freeware / share / gimp / scripts / truchet.scm.z / truchet.scm
Encoding:
Text File  |  1999-07-21  |  5.2 KB  |  176 lines

  1.  
  2. ; The GIMP -- an image manipulation program
  3. ; Copyright (C) 1995 Spencer Kimball and Peter Mattis
  4. ;
  5. ; This program is free software; you can redistribute it and/or modify
  6. ; it under the terms of the GNU General Public License as published by
  7. ; the Free Software Foundation; either version 2 of the License, or
  8. ; (at your option) any later version.
  9. ; This program is distributed in the hope that it will be useful,
  10. ; but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12. ; GNU General Public License for more details.
  13. ; You should have received a copy of the GNU General Public License
  14. ; along with this program; if not, write to the Free Software
  15. ; Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  16. ;
  17. ;    Truchet  - a script to create Truchet patterns 
  18. ;                 by Adrian Likins <aklikins@eos.ncsu.edu>
  19. ;                 http://www4.ncsu.edu/~aklikins/
  20. ;    version about .8 give or take
  21. ;
  22. ;  Lots of thanks to Quartic for his help.
  23. ;
  24. ;
  25. ;         The utility of this script is left as an exercise for the reader.
  26.  
  27. (define (center-ellipse img cx cy rx ry op aa feather frad)
  28.   (gimp-ellipse-select img (- cx rx) (- cy ry) (+ rx rx ) (+ ry ry ) op aa feather frad))
  29.  
  30. (define (use-tiles img drawable height width img2 drawable2 xoffset yoffset)
  31.   (gimp-edit-copy img2 drawable2)
  32.   (let ((floating-sel (car (gimp-edit-paste img drawable FALSE))))
  33.     (gimp-layer-set-offsets floating-sel xoffset yoffset)
  34.     (gimp-floating-sel-anchor floating-sel)
  35.     )
  36. )
  37.  
  38.  
  39. (define (create-tiles img drawable1 drawable2 size thickness backcolor forecolor)
  40.   (let* (
  41.      (half-thickness (/ thickness 2))
  42.      (outer-radius (+ (/ size 2) half-thickness))
  43.      (inner-radius (- (/ size 2) half-thickness))
  44.      )
  45.  
  46.     (gimp-selection-all img)
  47.     (gimp-palette-set-background backcolor)
  48.     (gimp-edit-fill img drawable1)
  49.  
  50.     (let* (
  51.        (tempSize (* size 3))
  52.        (temp-img (car (gimp-image-new tempSize tempSize RGB))) 
  53.        (temp-draw (car (gimp-layer-new temp-img tempSize tempSize RGB_IMAGE "Jabar" 100 NORMAL)))
  54.       )
  55.       (gimp-image-disable-undo temp-img)
  56.       (gimp-image-add-layer temp-img temp-draw 0)
  57.       (gimp-palette-set-background backcolor)
  58.       (gimp-edit-fill temp-img temp-draw)
  59.       
  60.       
  61.       (center-ellipse temp-img size size outer-radius outer-radius REPLACE TRUE FALSE 0)
  62.       (center-ellipse temp-img size size inner-radius inner-radius SUB TRUE FALSE 0)
  63.       
  64.       (center-ellipse temp-img (* size 2) (*  size 2)  outer-radius outer-radius ADD TRUE FALSE 0)
  65.       (center-ellipse temp-img (* size 2) (*  size 2)  inner-radius inner-radius SUB TRUE FALSE 0)
  66.       (gimp-palette-set-background forecolor)
  67.       (gimp-edit-fill temp-img temp-draw)
  68.       
  69.       (gimp-selection-none temp-img)
  70.  
  71.       (gimp-image-resize temp-img size size (- size) (- size))
  72.       ; woo hoo it works....finally...
  73.  
  74.  
  75.       (gimp-selection-all temp-img)
  76.       (gimp-edit-copy temp-img temp-draw)
  77.       (let ((floating-sel (car (gimp-edit-paste img drawable2 FALSE))))
  78.     (gimp-floating-sel-anchor floating-sel))
  79.  
  80.       
  81.       (let ((floating-sel (car (gimp-edit-paste img drawable1 FALSE))))
  82.     (gimp-floating-sel-anchor floating-sel))
  83.  
  84.       (let ((drawble (car (gimp-flip img drawable1 0)))))
  85.     
  86.  
  87.       ;(gimp-display-new temp-img)
  88.       (gimp-image-delete temp-img)
  89.       )
  90.     )
  91. )  
  92.  
  93.  
  94. (define (script-fu-truchet size thickness backcolor forecolor xtiles ytiles)
  95.   (let* (     
  96.      (width (* size xtiles))
  97.      (height (* size ytiles))
  98.      (img (car (gimp-image-new width height RGB)))
  99.      (tile (car (gimp-image-new size size RGB)))
  100.      (layer-one (car (gimp-layer-new img width height RGB "Rambis" 100 NORMAL)))
  101.      (tiledraw1 (car (gimp-layer-new tile size size RGB "Johnson" 100 NORMAL)))
  102.      (tiledraw2 (car (gimp-layer-new tile size size RGB "Cooper" 100 NORMAL)))
  103.      (Xindex 0)
  104.      (Yindex 0) 
  105.      )
  106.  
  107.     (gimp-image-disable-undo img)
  108.     (gimp-image-disable-undo tile)
  109.     
  110.     (gimp-image-add-layer img layer-one 0)
  111.     (gimp-image-add-layer tile tiledraw1 0)
  112.     (gimp-image-add-layer tile tiledraw2 0)
  113.  
  114.  
  115.     ;just to look a little better
  116.     (gimp-selection-all img)
  117.     (gimp-palette-set-background backcolor) 
  118.     (gimp-edit-fill img layer-one)
  119.     (gimp-selection-none img)
  120.  
  121.     (create-tiles tile tiledraw1 tiledraw2 size thickness backcolor forecolor)
  122.     
  123.  
  124.     (while (<= Xindex xtiles)
  125.        (while (<= Yindex ytiles)
  126.           (if (= (rand 2) 0)
  127.               (use-tiles img layer-one height width tile tiledraw1 (* Xindex size) (* Yindex size))
  128.               (use-tiles img layer-one height width tile tiledraw2 (* Xindex size) (* Yindex size))
  129.               )
  130.           (set! Yindex (+ Yindex 1))
  131.           )
  132.        (set! Yindex 0)
  133.        (set! Xindex (+ Xindex 1))
  134.        )
  135.     
  136.     
  137.     (gimp-image-delete tile)
  138.     (gimp-display-new img)
  139.     (gimp-image-enable-undo img)
  140.     )
  141.   )
  142.  
  143. (script-fu-register "script-fu-truchet"
  144.             "<Toolbox>/Xtns/Script-Fu/Patterns/Truchet"
  145.             "Create a Truchet pattern"
  146.             "Adrian Likins <aklikins@eos.ncsu.edu>"
  147.             "Adrian Likins"
  148.             "1997"
  149.             ""
  150.             SF-VALUE "Block Size" "32"
  151.             SF-VALUE "Thickness" "2"
  152.             SF-COLOR "Background Color" '(255 255 255)
  153.             SF-COLOR "Foreground Color" '(0 0 0)
  154.             SF-VALUE "Number of Xtiles" "5"
  155.             SF-VALUE "Number of Ytiles" "5"
  156.             )
  157.  
  158.  
  159.  
  160.  
  161.  
  162.  
  163.  
  164.  
  165.  
  166.  
  167.  
  168.  
  169.  
  170.  
  171.  
  172.  
  173.  
  174.